using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.Design;
using System.Security.Policy;
using System.Text;
using System.Windows.Media;
using System.Xml.Linq;

namespace RRX.Xml.ProjectTree
{
    public class ItemProjectTreeXml : INotifyPropertyChanged, IItemProjectTree
    {

        public ItemProjectTreeXml() { }


        // ---------- Properties ----------
        private string name { get; set; } = "Xml";
        public string Name
        {
            get => name;
            set
            {
                name = value;
                OnPropertyChanged("Name");
            }
        }

        private string content { get; set; } = string.Empty;
        public string Content
        {
            get => content;
            set
            {
                content = value;
                OnPropertyChanged("Content");
            }
        }





        // ---------- Basic ----------
        private ObservableCollection<IItemProjectTree> children { get; set; } = new ObservableCollection<IItemProjectTree>();
        public ObservableCollection<IItemProjectTree> Children
        {
            get => children;
            set
            {
                children = value;
                OnPropertyChanged("Children");
            }
        }



        // ---------- Functions ----------
        public IItemProjectTree Copy()
        {
            ItemProjectTreeXml copy = new ItemProjectTreeXml();
            copy.name = name;
            copy.content = content;

            return copy;
        }

        public XElement Xml()
        {
            XElement xml = new XElement("xml");

            foreach (IItemProjectTree item in Children)
            {
                xml.Add(item.Xml());
            }

            return xml;
        }


        // ---------- PropertyChanged ----------
        public event PropertyChangedEventHandler PropertyChanged;

        protected void OnPropertyChanged(string name)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
        }
    }
}
